package io.gitee.chearnee.fw.openapi.constant.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import io.gitee.chearnee.fw.common.model.IBaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 资源类型
 *
 * @author yangzhi
 * @Date 2021/9/23 11:20
 **/
@Getter
@AllArgsConstructor
public enum ResourcesTypeEnum implements IBaseEnum<String> {
  /**
   * 默认
   */
  DEFAULT("default", 0, "默认"),
  /**
   * 项目
   */
  PROJECT("project", 1, "项目"),
  /**
   * 企业
   */
  COMPANY("company", 2, "企业"),
  /**
   * 产品
   */
  PRODUCT("product", 3, "产品");
  private static final Map<Integer, ResourcesTypeEnum> map = Arrays
      .stream(ResourcesTypeEnum.values())
      .collect(Collectors.toMap(ResourcesTypeEnum::getCode, vo -> vo));
  private final String value;
  @EnumValue
  private final Integer code;
  private final String desc;

  public static ResourcesTypeEnum getByCode(Integer code) {
    ResourcesTypeEnum value = map.get(code);
    if (null == value) {
      value = DEFAULT;
    }
    return value;
  }

}
